<?php

class DefaultController extends Controller {

    public $content = array();
    public $i = 0;

    public function actionIndex() {
        $this->layout = 'main_search';
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/theme.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/base.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/css.css");

        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/account_settings.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/search.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/jquery-ui.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/chat.css");


        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-1.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/lib.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/onload.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/community.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-1.9.1.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/lib.json2.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-ui-1.9.2.custom.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-mods.js");

        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/peoplemedia.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/peoplemedia_rtn_slide.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/logger.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/peoplemedia.theming.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/stacktrace-min-0.3.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery.ba-bbq.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/index.js");

        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery.cookie.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery.base64.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/moment.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/logger.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/pmchat-1.0.js?d=20131009.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/pmchat.ui-1.0.js?d=20131009.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/search/index.js");

        if (isset($_GET['UsernameSearchTextBox'])) {

            $criteria = new CDbCriteria();
            if ($_GET['searchmethod'] == 1) {
                $criteria->addCondition('username=:username');
                $criteria->params[':username'] = $_GET['UsernameSearchTextBox'];
            } if ($_GET['searchmethod'] == 0) {
                $criteria->addSearchCondition('username', $_GET['UsernameSearchTextBox']);
            } else {

                $criteria->addCondition('username=:username');
            }
            $i = User::model()->count($criteria);
            $pages = new CPagination(User::model()->count($criteria));
            $pages->pageSize = 10;
            $pages->applyLimit($criteria);
            $models = User::model()->with('profile')->findAll($criteria);
        }
        $this->render('index', compact('models', 'pages', 'i'));
    }

    public function actionSearchUser() {
        $this->content['searchuser'] = 1;
        $this->render('searchuser', array('searchuser' => 1));
    }

}
